package org.jumiz.db;

import java.sql.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
public class DbFormatMain {
    public static void main(String[] args) {
        DbConfig dbConfig = new DbConfig();
        dbConfig.setDriverClass("com.mysql.cj.jdbc.Driver");
        dbConfig.setUrl("jdbc:mysql://build-mysql:3306/build_business_boot_ctsw?useUnicode=true&characterEncoding=utf-8&user=root&password=Yun0501.");
        DocDBOnLineUtilZ.config = dbConfig;
        Connection connection = DocDBOnLineUtilZ.getConnection();
        try {
            String sql = "select smi.id, smi.material_name, ssc.supplier_classify_name " +
                    "from supplies_material_info smi \n" +
                    "left join supplies_supplier_classify ssc on smi.material_classify_num = ssc.supplier_classify_num";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount = metaData.getColumnCount();

            String fileds = sql.substring(6, sql.indexOf("from"));
            List<String> collect = Arrays.asList(fileds.split(",")).stream().map(item -> {
                if (item.indexOf(".") > 0) {
                    return item.substring(item.indexOf(".") + 1);
                }
                return item;
            }).collect(Collectors.toList());
            System.out.println(sql);

            HashMap<String, String> map = new HashMap<>();
            for (int i = 1; i <= columnCount; i++) {
                map.put(metaData.getColumnName(i), metaData.getColumnName(i));
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
